﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace LIB
{
    public class XMLSerialization
    {
        static public void SerializeToXML<T>(T movie,string path)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(T));
            System.IO.TextWriter textWriter = new StreamWriter(path);
            serializer.Serialize(textWriter, movie);
            textWriter.Close();
        }
        static public List<T> DeserializeFromXML<T>(string path)
        {
            XmlSerializer deserializer = new XmlSerializer(typeof(List<T>));
            TextReader textReader = new StreamReader(path);
            List<T> movies;
            movies = (List<T>)deserializer.Deserialize(textReader);
            textReader.Close();
            return movies;
        }
        static public T Deserialize<T>(string path)
        {
            XmlSerializer deserializer = new XmlSerializer(typeof(T));
            TextReader textReader = new StreamReader(path);
            T movies;
            movies = (T)deserializer.Deserialize(textReader);
            textReader.Close();
            return movies;
        }
    }
}
